<template>
	<!-- 首页灵活用工详情页组件 -->
	<view class="main">
			<u-sticky>
		<view class="search">
			<u-search :show-action='true' placeholder="请输入工作/工种名称" @custom="search" v-model="keyword"></u-search>
		</view>
		</u-sticky>
		<view class="register">
			<view class="item_three" @click="goFabu">
				<image src="https://recruit-oss.oss-cn-beijing.aliyuncs.com/recruit/img/v1/xinjianxinxi.png" mode="heightFix"></image>
				<text>发布招工信息</text>
			</view>
			<view class="item_three" @click="gofjyz">
				<image src="https://recruit-oss.oss-cn-beijing.aliyuncs.com/recruit/img/v1/fujinyizhan.png" mode="heightFix"></image>
				<text>附近企业</text>
			</view>
			<view class="item_three" @click="goWode('招工')">
				<image src="https://recruit-oss.oss-cn-beijing.aliyuncs.com/recruit/img/v1/wodefabu.png" mode="heightFix"></image>
				<text>我的发布</text>
			</view>
			<view class="item_three" @click="bmjl">
				<image src="https://recruit-oss.oss-cn-beijing.aliyuncs.com/recruit/img/v1/baomingjilu.png" mode="heightFix"></image>
				<text>用工记录</text>
			</view>
		</view>

		<view class="hotWork">
			<u-sticky offset-top="80">
				<view class="title">
					<view class="left">
						<view class="tabs" @click="change('热门')">
							<text :class="{'active':type=='热门'}">热门零工</text>
							<view class="line" v-if="type=='热门'"></view>
						</view>
						<view class="tabs" @click="change('附近')">
							<text :class="{'active':type=='附近'}">附近零工</text>
							<view class="line" v-if="type=='附近'"></view>
						</view>
					</view>
					<view class="right">
						<!-- <u-button type="primary" size="mini">筛选</u-button> -->
					</view>
				</view>
			</u-sticky>
			<view style="margin-top: 150rpx;" v-if='lists.length==0'>
				<u-empty text="暂无数据" mode="list"></u-empty>
			</view>
			<view class="workItem" v-for="(item,index) in lists" :key="index" @click="goDetil(item.id)">
				<view class="header">
					<view class="left">
						<view>
							<image v-if="item.headimg" mode="heightFix" :src="item.headimg"></image>
							<image v-else mode="heightFix" src="https://recruit-oss.oss-cn-beijing.aliyuncs.com/recruit/img/v1/touxiang.png"></image>
						</view>
						<view class="info">
							<text class="name">{{item.realname}}</text>
							<view class="workName">{{item.work_name}}</view>
						</view>
					</view>
					<text class="money" >{{item.wages.replace(',', '')}}</text>
				</view>
				<view class="center">
					<view class="tags">
						<view class="tagItem1">{{item.create_type}}</view>
						<view class="tagItem">{{item.settlement}}</view>
						<view class="tagItem" v-if="item.info_type=='招工'">{{item.need_num}}人</view>
					</view>
					<view class="time">
						{{item.add_time.substring(0,10)}}
					</view>
				</view>
				<view class="footer">
					<text class="address">{{item.province+item.city+item.area+item.address}}</text>
			<text class="add1">
				{{ item.juli<1000?(item.juli || '')+'m':((item.juli/1000).toFixed(2) || '')+'km'}}
			</text>
				</view>
			</view>
			<view style="margin-top: 30rpx;">
				<u-loadmore style="margin-top: 30rpx;" :status="status" />
			</view>
		</view>
	</view>
</template>

<script>
		import api from '../../../../api/routes.js'
	export default {


		data() {
			return {
				page: 1,
				limit: 5,
				status: "loadmore",
				lists: [],
				// 拿到的数据总条数
				total: 0,
				//判断是否发送请求的条件
				load: false,
				keyword: '',
				ids:'',
				settle:'',
				type:'热门',

			};
		},
		onLoad() {
			let that = this
			wx.getLocation({
			 type: 'wgs84',
			 success (res) {
			   that.lat = res.latitude
			   that.lgt= res.longitude
			   that.getList()
			 }
			})
			this.getMapLocation()
		},
		onReachBottom() {
			if (this.status === "loadmore") {
				this.loadmore();
			}
		},
		
		

		methods: {
			// 判断是否开启定位
			getMapLocation(){
				wx.getLocation({
				 type: 'wgs84',
				 success (res) {
					 wx.setStorageSync("nowLat",res.latitude);
					 wx.setStorageSync("nowLgt",res.longitude);
					 },
				 fail() {
					console.log('未拿到经纬度！！');
					uni.showModal({
						title: '提示',
						content: '获取不到当前位置，请打开定位服务功能',
						
					})
				 }
				})
				
			},
			goDetil(id) {
				uni.navigateTo({
					url: '/package/pages/searchJob/other/detils?id=' + id + '&type=求职',
				});
			},
			search(val) {
				this.load = false;
				this.page = 1
				this.limit = 5
				this.status = 'loadmore'
				this.lists = []
				this.getList(val)
			},
			loadmore() {
				this.page++;
				this.getList();
			},
			async getList(val) {
				wx.showLoading()
				// 判断当前是否在请求，如果为true正在请求数据，就让他返回空，如果为false没在请求，就让它开始请求数据
				if (this.load) {
					return;
				}
				this.load = true;
				// 请求数据时，状态改为加载中状态
				this.status = "loading";
				const res = await this.$myRequest({
					url: api.lgInfoPageList,
					method: "POST",
					data: {
						page: this.page,
						limit: this.limit,
						"orderSort": this.type == '热门' ? 1 : 2, //排序方式:1-热门,2-附近
						"key": this.keyword, //搜索关键词,
						"wages": "", //薪资
						"settlement": "", // 结算方式
						"mbId": "", //用户ID, ~~~~传这个值时,代表查询我发布的 ,大多数都不传
						"infoType": "求职", //类型:招工  / 求职  (必传)，
						 "lgt":this.lgt,
						 "lat":this.lat,
						 "juli" :val
					},
				});
				console.log(res,808033333)
				this.load = false;
				if (res.data.code == 0) {
					// this.lists = res.data.page.list
					this.total = res.data.page.totalCount;
					this.lists = [...this.lists, ...res.data.page.list];
					// this.ids=res.data.page.id;
					// this.settle=res.data.page.settlement;
					// console.log(this.settle,'???');
					this.ismore();
					setTimeout(() => {
						wx.hideLoading()
					}, 2000)
				} else {
					wx.showToast({
						title: '查询失败',
						icon: 'none'
					})
				}
				console.log(res.data.page.list)
			},
			ismore() {
				if (this.total === this.lists.length) {
					this.status = "nomore";
				} else {
					this.status = "loadmore";
				}
			},
			change(val) {
				let that=this;
				this.type = val
				wx.getLocation({
				 type: 'wgs84',
				 success (res) {
				  if(val=="附近"){
				  	that.search(1)
				  }else{
				  	that.search()
				  }
				 },
				 fail() {
				console.log('未拿到经纬度！！');
				uni.showModal({
					title: '提示',
					content: '获取不到当前位置，请打开定位服务功能',
					
				})
				 }
				})
				
			},
			gofjyz(){
				uni.navigateTo({
					url: '/package/pages/searchJob/other/fujinyizhan',
				});
			},
			goWode(val){
				uni.navigateTo({
					url: '/package/pages/searchJob/other/wodefabu?type='+val,
				});
			},
			bmjl(){
				uni.navigateTo({
					url: '/package/pages/searchJob/other/baomingjilu',
				});
			},
			goFabu() {
				uni.navigateTo({
					url: '/package/pages/searchJob/other/addInfo1',
				});
			},
			lgRegister() {
				console.log("林工登记！！！");
				uni.navigateTo({
					url: '/package/pages/components/lingGonRegister',
				});
			}
		},
	};
</script>

<!-- <style>
/* #ifndef H5 */
page {
  height: 100%;
  background-color: #f2f2f2;
}

/* #endif */
</style> -->

<style lang="scss" scoped>
	.main {
		background: #EDEDED;
	}

	.search {
		background: white;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		padding-left: 10rpx;
	}

	.register {
		height: 180rpx;
		background: white;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		padding-top: 20rpx;
		padding-bottom: 20rpx;

		.item_three {
			width: 25%;
			height: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #303133;
			font-size: 24rpx;
			flex-direction: column;

			image {
				// width: 128rpx;
				// height: 128rpx;
				border-radius: 10px;
				// height: 80rpx;
			}
		}

	}

	.hotWork {
		background: white;

		.title {
			font-family: Arial, Helvetica, sans-serif;
			margin-left: 3%;
			display: flex;
			color: #909399;
			justify-content: space-between;
			background: white;
			font-size: 32rpx;
			.tabs {
				margin-right: 30rpx;

				.line {
					width: 30rpx;
					height: 4px;
					background: #1684fd;
					// background: #000088;
					margin-left: 46rpx;
					// border-radius: 0 0 10rpx 10rpx;
				}
			}

			.active {
				color: #333;
				font-weight: bold;
			}

			.left {
				display: flex;
			}

			.right {
				margin-right: 3%;
			}

		}

		.workItem {
			width: 94%;
			margin-left: 3%;
			height: 240rpx;
			border-radius: 6px;
			box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
			margin-top: 20rpx;

			// .header{
			// 	height:90rpx;
			// 	.name{
			// 		color: #333;
			// 		font-size: 30rpx;
			// 		font-weight: 500;
			// 		font-family: Arial, Helvetica, sans-serif;
			// 	}
			// 	.money{
			// 		color: orange;
			// 		font-size: 28rpx;
			// 		font-weight: 500;
			// 		font-family: Arial, Helvetica, sans-serif;
			// 	}
			// }
			.header {
				height: 90rpx;

				.left {
					display: flex;
					margin-top: 20rpx;

					.info {
						display: flex;
						flex-direction: column;
						margin-left: 20rpx;
					}

					image {
						height: 70rpx;
						border-radius: 50%;
					}

					.name {
						color: #333;
						font-size: 34rpx;
						font-weight: bold;
						font-family: Arial, Helvetica, sans-serif;
					}
					.workName{
						color: #1684FC;
						font-size: 28rpx;
						font-weight: 500;
						line-height: 46rpx;
						font-family: Arial, Helvetica, sans-serif;
					}

					.name1 {
						color: #1684fd;
						font-size: 26rpx;
						font-family: Arial, Helvetica, sans-serif;
					}
				}

				.money {
					color:#F75E54;
					font-size: 30rpx;
					font-weight: 500;
					font-family: Arial, Helvetica, sans-serif;
				}
			}

			.center {
				height: 75rpx;
				border-bottom: 1px solid #E4E7ED;

				.time {
					color: #000000;
					font-size: 28rpx;
					font-family: Arial, Helvetica, sans-serif;
				}

				.tags {
					display: flex;

					.tagItem{
						font-size: 24rpx;
						margin-right: 15rpx;
						padding:4rpx 10rpx 4rpx 10rpx;
						border-radius: 2px;
						background: #DBF1E1;
						color: #19BE6B;
					}
					.tagItem1{
						font-size: 24rpx;
						margin-right: 15rpx;
						padding:4rpx 10rpx 4rpx 10rpx;
						border-radius: 2px;
						background: #FDF6EC;
						color: #FCBD71;
					}

				}
			}

			.footer {
				height: 75rpx;

				.address {
					color: #414144;
					font-size:30rpx;
					font-family: Arial, Helvetica, sans-serif;
					width: 80%;
					white-space: nowrap;
					overflow: hidden;       
					text-overflow: ellipsis; 
					width: 70%;
				}

				.add1 {
					color: #5B81B8;
					font-size: 26rpx;
					font-family: Arial, Helvetica, sans-serif;
				}
			}

			.header,
			.center,
			.footer {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 96%;
				margin-left: 2%;
			}
		}
	}
</style>
